//
//  XMFollowViewController.m
//  XunMi
//
//  Created by MacBook on 2024/4/3.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMFollowViewController.h"
#import <JXCategoryView/JXCategoryView.h>
#import "XMFollowListViewController.h"

@interface XMFollowViewController () <JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;

@end

@implementation XMFollowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSubviews];
}

#pragma mark - setupSubViews
- (void)setupSubviews {
    [self.navView addSubview:self.categoryView];
    self.categoryView.listContainer = self.listContainerView;

    [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.navView).offset(15);
        make.right.equalTo(self.navView).offset(-15);
        make.top.equalTo(self.navView).offset(kStatusBarHeight);
        make.height.mas_equalTo(44);
    }];

    [self.view addSubview:self.listContainerView];
    [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(kNavBarAndStatusBarHeight, 0, 0, 0));
    }];

    [self.listContainerView.scrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
}

#pragma mark - JXCategoryListContainerViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return 2;
}

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    XMFollowListViewController *vc = [[XMFollowListViewController alloc] init];
    vc.index = index + 1;
    return vc;
    
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}

#pragma mark - JXPagerMainTableViewGestureDelegate
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
        return NO;
    }
    return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}

#pragma mark - Getter
- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavBarHeight)];
        _categoryView.backgroundColor = [UIColor clearColor];
        _categoryView.delegate = self;
        _categoryView.titleColor = kHEX(@"#1F1F1F");
        _categoryView.titleSelectedColor = kAppMainColor;
        _categoryView.titleFont = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
//        _categoryView.titleSelectedFont = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];

        _categoryView.titleColorGradientEnabled = YES;
        _categoryView.titleLabelZoomEnabled = YES;
//        _categoryView.titleLabelZoomScale = 1.0;
        _categoryView.titleLabelStrokeWidthEnabled = YES;

        JXCategoryIndicatorImageView *indicatorImageView = [[JXCategoryIndicatorImageView alloc] init];
        indicatorImageView.indicatorImageView.image = [UIImage imageNamed:@"bag_line"];
        indicatorImageView.indicatorImageViewSize = CGSizeMake(14, 6);
        indicatorImageView.verticalMargin = 5;
        _categoryView.indicators = @[indicatorImageView];
        _categoryView.titles = @[@"关注我的", @"我的关注"];
    }
    return _categoryView;
}

- (JXCategoryListContainerView *)listContainerView {
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    }
    return _listContainerView;
}

@end
